<?php

namespace App\Http\Controllers\Customer;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Facades\Services\OrderService;
use ValiDate;

class OrderController extends Controller
{
    public function addOrder(Request $request){
    	$rules = [
    		'commodity_id' => 'required|exists:commodities,id',
    		'commodity_number' => 'required'
    	];

    	ValiDate::validate($request,$rules);

    	$data = $request->all();

    	OrderService::addOrder($data);

    	return formatJsonResponse();
    }

    public function getOrders(){
    	return formatJsonResponse(OrderService::getOrdersByCustomer());
    }

    public function getOrder(Request $request){

    	$rules = [
    		'id' => 'required|exists:orders,id'
    	];

    	ValiDate::validate($request,$rules);

    	$data = $request->all();

    	return formatJsonResponse(OrderService::getOrderByCustomer($data));
    }
}
